/*
 * Copyright (c) 2015-2018 Sfkj Science And Technology Co.,Ltd.
 * All Rights Reserved.
 * This software is the confidential and proprietary information of
 * Sfkj Science And Technology Co.,Ltd.
 * ("Confidential Information").You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sfkj.
 */
package com.sfkj.walk.query.activity;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.annotations.QueryTransient;
import com.querydsl.core.types.Predicate;
import com.sfkj.walk.api.activity.ActivityType;
import com.sfkj.walk.mongo.AbstractDocument;
import com.sfkj.walk.query.user.User;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.axonframework.domain.DateTimeRange;
import org.axonframework.domain.ImageUrl;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.Indexed;

@Data
@EqualsAndHashCode(callSuper = true)
public class Activity extends AbstractDocument {

    private static final long serialVersionUID = 8118041918500730458L;

    private ActivityType activityType;
    private String title;
    private String introduction;
    private ImageUrl coverUrl;
    private DateTimeRange time;
    @Indexed
    private Integer year;
    @Indexed
    private Integer month;
    @Indexed
    private String creatorId;
    private Long memberCount;
    private Long noteCount;
    private Long viewCount;
    private Long collectCount;

    @Transient
    @QueryTransient
    private User creator;
    @Transient
    @QueryTransient
    private Boolean isMy;
    @Transient
    @QueryTransient
    private Boolean isMember;

    public static Predicate buildBy(String id) {
        BooleanBuilder conditions = new BooleanBuilder();
        conditions.and(QActivity.activity.id.eq(id));
        return conditions;
    }

    public static Predicate buildByCreatorId(String creatorId, boolean isMy) {
        BooleanBuilder conditions = new BooleanBuilder();
        conditions.and(QActivity.activity.creatorId.eq(creatorId));
        if (!isMy) {
            conditions.and(QActivity.activity.activityType.eq(ActivityType.PUBLIC));
        }
        return conditions;
    }
}